<template>
	<view class="index">
		<scroll-view class="scroll f-1 bf8 db" scroll-y="true">
			<!--简洁 -->
			<view class="f-1 p10 bff1">
				<view class="box" v-for="(item,i) in orderList" :key="i">
					<view class="prid">
						<view class="titlename">{{item.name}}</view>
						<view class="jiao">
							<!-- 角标 -->
							<view class="jiaohang">
								<text class="label">是否加价：</text>
								<u-tag mode="light" :text="is_skuList[item.is_sku].name"
									:type="is_skuList[item.is_sku].type" plain />
							</view>
						</view>
					</view>
					<!-- 操作 -->
					<view class="f-x-e mt10 pt10 bt1">
						<view class="f-g-0 w30 p-0-10" @click="edit(item)">
							<u-button type="primary" :customStyle="{marginLeft: '20rpx',color:'#000'}" text="编辑"
								color="#ffaa00" :plain="true" shape="circle" size="medium">
							</u-button>
						</view>
						<view class="f-g-0 w30 p-0-10" @click="deleteItem(item)">
							<u-button type="primary" :customStyle="{marginLeft: '20rpx',color:'#000'}" text="删除"
								color="#ffaa00" :plain="true" shape="circle" size="medium">
							</u-button>
						</view>
					</view>
				</view>
				<view class="zhanwei"></view>
			</view>
		</scroll-view>
		<view class="f-g-1 goodw guding">
			<view class="navbar2 bt f-row">
				<view class="f-1 f-row bf">
					<template v-for="(v, i) in navs">
						<view class="f-1 f-y-c" @click="djTab(v)" :key="i">
							<view class="wh f-c f-y-c">
								<text class="cf7c mr10" :style="{ color: subColor ,fontSize:'38rpx'}"
									:class="['icon' + v.i, 'iconfont f20']"></text>
								<view class="">{{ v.t }}</view>
							</view>
						</view>
					</template>
				</view>
			</view>
		</view>
		<u-modal :show="show" :content="content" :showCancelButton="true" @cancel="closeshow" @close="closeshow"
			@confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				queryForm: {
					pageNo: 1,
					pageSize: 10,
				},
				orderList: [],
				is_skuList: {
					'0': {
						type: 'error',
						name: '否',
					},
					'1': {
						type: 'success',
						name: '是',
					},
				},
				subColor: uni.getStorageSync('subject_color'),
				navs: [{
					i: '-jiahao',
					k: 'xjsp',
					url: 'xzlx',
					t: '新建规格组'
				}],
				show: false,
				content: '',
				activeObj: {},
			}
		},
		onLoad() {},
		onShow() {
			//获取数据
			this.getDianPrList();
		},
		watch: {

		},
		methods: {
			djTab(v) {
				if (v.url == 'xzlx') {
					uni.navigateTo({
						url: `/pages/home/diandan/guigezu/model/save`
					})
				}
			},
			edit(val) {
				uni.navigateTo({
					url: `/pages/home/diandan/guigezu/model/save?id=` + val.id
				})
			},
			deleteItem(val) {
				this.activeObj = val;
				this.content = '是否删除该规格组？';
				this.show = true;
			},
			async confirm() {
				let {
					code,
					msg
				} = await this.beg.request({
					url: '/admin/product.Attr/deleted',
					method: 'POST',
					data: {
						id: this.activeObj.id,
						is_deleted: 1
					},
				})
				if (code == 1) {
					this.fetchData();
					this.activeObj = {};
					this.show = false;
				}
				uni.$u.toast(msg)
			},
			closeshow() {
				this.show = false;
			},
			getDianPrList() {
				this.fetchData();
			},
			async fetchData() {
				this.status = 'loading'
				let {
					data: {
						data,
						count
					},
				} = await this.beg.request({
					url: '/admin/product.Attr/index',
					method: 'POST',
					data: {
						page: this.queryForm.pageNo,
						limit: this.queryForm.pageSize,
						id: '',
						name: '',
						is_deleted: 0
					},
				})
				if (this.queryForm.pageNo == 1) {
					this.orderList = data
				} else {
					if (data.length == 0) {
						this.status = 'nomore'
						return
					}
					this.orderList = this.orderList.concat(data)
				}
				this.status = 'loadmore'
				this.time = ''
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		background-color: #fff;
		padding: 20rpx;
		line-height: 1.5;
		position: relative;
		margin-top: 20rpx;
		border-radius: 20rpx;



		.prid {
			font-weight: bold;
			font-size: 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.titlename {
				width: 70%;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.jiao {
				width: 30%;
				right: 10rpx;

				.jiaohang {
					display: flex;
					align-items: center;

					.label {
						font-size: 20rpx;
						font-weight: 500;
					}

					.rijianju {
						margin-right: 10rpx;
					}
				}
			}
		}

		.prod {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;
		}

		.prname {
			width: 80%;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}

		.price {
			width: 20%;
			text-align: right;
		}
	}

	.zhanwei {
		height: 100rpx;
	}

	.guding {
		width: 100%;
		height: 100rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.u-button {
		height: 60rpx;
		width: 100%;
	}
</style>